GetTileRectImage(Int32,Rectangle,Int32,EventHandler<ProgressEventArgs>) Method (Jpeg2000Page)
In This Topic
Returns an image of specified region of specified tile of this page, decoded with the specified number of wavelet levels.
Syntax
Parameters
- tileIndex
- Zero based index of tile.
- region
- Rectangle, in tile, to decode.
- waveletLevels
- The number of discrete wavelet transformation levels (decomposition levels).
- imageLoadingProgress
- Delegate of the image loading progress. Can be set to null (Nothing in Visual Basic).
Return Value
Image of specified region of specified tile of this page.
Remarks
Tile decoded unscaled if waveletLevels equals to WaveletLevels; otherwise, tile decoded with scale (2 in power (WaveletLevels - waveletLevels)).
Example
This C#/VB.NET code shows how to open a JPEG2000 file and get its first tile's image by parts.
' Opens JPEG2000 file and gets its first tile's image by parts.
Public Shared Function GetJpeg2000TileByParts(jpeg2000Filename As String) As Vintasoft.Imaging.VintasoftImage
' open an existing JPEG2000 file
Using file As New Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000File(jpeg2000Filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)
' get JPEG2000 page
Dim page As Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000Page = file.Page
' get page dimensions and pixel format
Dim imageWidth As Integer = page.Width
Dim imageHeight As Integer = page.Height
Dim palette As Vintasoft.Imaging.Palette = If(page.Palette IsNot Nothing, page.Palette, New Vintasoft.Imaging.Palette())
Dim imageInfo As New Vintasoft.Imaging.Codecs.Decoders.ImageInfo(imageWidth, imageHeight, page.BitsPerPixel, palette, page.Resolution)
Dim pixelFormat As Vintasoft.Imaging.PixelFormat = imageInfo.PixelFormat
' get first tile rectangle
Dim firstTileRectangle As System.Drawing.Rectangle = page.GetTileGrid()(0)
' get tile dimensions
Dim tileWidth As Integer = firstTileRectangle.Width
Dim tileHeight As Integer = firstTileRectangle.Height
' if tile is too small, then get tile at once
If tileWidth = 1 OrElse tileHeight = 1 Then
Return page.GetTileRectImage(0, New System.Drawing.Rectangle(0, 0, tileWidth, tileHeight), Nothing)
End If
' divide tile rectangle into 4 rectangles
Dim grid As System.Drawing.Rectangle() = New System.Drawing.Rectangle(3) {}
grid(0) = New System.Drawing.Rectangle(0, 0, tileWidth \ 2, tileHeight \ 2)
grid(1) = New System.Drawing.Rectangle(tileWidth \ 2, 0, (tileWidth + 1) \ 2, tileHeight \ 2)
grid(2) = New System.Drawing.Rectangle(0, tileHeight \ 2, tileWidth \ 2, (tileHeight + 1) \ 2)
grid(3) = New System.Drawing.Rectangle(tileWidth \ 2, tileHeight \ 2, (tileWidth + 1) \ 2, (tileHeight + 1) \ 2)
' get number of wavelet levels
Dim waveletLevel As Integer = page.WaveletLevels
' create a VintasoftImage object
Dim resultImage As New Vintasoft.Imaging.VintasoftImage(tileWidth, tileHeight, pixelFormat)
' for each part of tile
For i As Integer = 0 To 3
' get current rectangle
Dim rectangle As System.Drawing.Rectangle = grid(i)
' get current rectangle location
Dim position As System.Drawing.Point = rectangle.Location
' get image of current rectangle
Using rectImage As Vintasoft.Imaging.VintasoftImage = page.GetTileRectImage(0, rectangle, waveletLevel, Nothing)
' overlay rectangle image on result image
Dim overlayCommand As New Vintasoft.Imaging.ImageProcessing.OverlayCommand(rectImage, position)
overlayCommand.ExecuteInPlace(resultImage)
End Using
Next
Return resultImage
End Using
End Function
// Opens JPEG2000 file and gets its first tile's image by parts.
public static Vintasoft.Imaging.VintasoftImage GetJpeg2000TileByParts(string jpeg2000Filename)
{
// open an existing JPEG2000 file
using (Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000File file =
new Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000File(
jpeg2000Filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
// get JPEG2000 page
Vintasoft.Imaging.Codecs.ImageFiles.Jpeg2000.Jpeg2000Page page = file.Page;
// get page dimensions and pixel format
int imageWidth = page.Width;
int imageHeight = page.Height;
Vintasoft.Imaging.Palette palette = page.Palette != null ? page.Palette : new Vintasoft.Imaging.Palette();
Vintasoft.Imaging.Codecs.Decoders.ImageInfo imageInfo =
new Vintasoft.Imaging.Codecs.Decoders.ImageInfo(
imageWidth,
imageHeight,
page.BitsPerPixel,
palette,
page.Resolution);
Vintasoft.Imaging.PixelFormat pixelFormat = imageInfo.PixelFormat;
// get first tile rectangle
System.Drawing.Rectangle firstTileRectangle = page.GetTileGrid()[0];
// get tile dimensions
int tileWidth = firstTileRectangle.Width;
int tileHeight = firstTileRectangle.Height;
// if tile is too small, then get tile at once
if (tileWidth == 1 || tileHeight == 1)
return page.GetTileRectImage(0, new System.Drawing.Rectangle(0, 0, tileWidth, tileHeight), null);
// divide tile rectangle into 4 rectangles
System.Drawing.Rectangle[] grid = new System.Drawing.Rectangle[4];
grid[0] = new System.Drawing.Rectangle(0, 0, tileWidth / 2, tileHeight / 2);
grid[1] = new System.Drawing.Rectangle(tileWidth / 2, 0, (tileWidth + 1) / 2, tileHeight / 2);
grid[2] = new System.Drawing.Rectangle(0, tileHeight / 2, tileWidth / 2, (tileHeight + 1) / 2);
grid[3] = new System.Drawing.Rectangle(tileWidth / 2, tileHeight / 2, (tileWidth + 1) / 2, (tileHeight + 1) / 2);
// get number of wavelet levels
int waveletLevel = page.WaveletLevels;
// create a VintasoftImage object
Vintasoft.Imaging.VintasoftImage resultImage =
new Vintasoft.Imaging.VintasoftImage(tileWidth, tileHeight, pixelFormat);
// for each part of tile
for (int i = 0; i < 4; i++)
{
// get current rectangle
System.Drawing.Rectangle rectangle = grid[i];
// get current rectangle location
System.Drawing.Point position = rectangle.Location;
// get image of current rectangle
using (Vintasoft.Imaging.VintasoftImage rectImage = page.GetTileRectImage(0, rectangle, waveletLevel, null))
{
// overlay rectangle image on result image
Vintasoft.Imaging.ImageProcessing.OverlayCommand overlayCommand =
new Vintasoft.Imaging.ImageProcessing.OverlayCommand(rectImage, position);
overlayCommand.ExecuteInPlace(resultImage);
}
}
return resultImage;
}
}
Requirements
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also